﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StudentInfoSystem.View
{
    public partial class StudentQueryForm : Form
    {
        public StudentQueryForm()
        {
            InitializeComponent();
            InitializeGridView();
            InitializeGroupComboBox();
        }

        public void InitializeGridView()
        {
            var students = Data.StudentDataAccess.GetAllStudents();
            this.dataGridView1.DataSource = students;
        }

        public void InitializeGroupComboBox()
        {
            var groups = Data.StudentDataAccess.GetStudentGroups();
            this.comboBox1.Items.Add("All Groups");
            this.comboBox1.SelectedIndex = 0;
            foreach (var currentGroups in groups)
            {
                this.comboBox1.Items.Add(currentGroups.Group);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex == 0)
            {
                InitializeGridView();
            }
            else
            {
                var students = Data.StudentDataAccess.GetStudentsByGroup(Convert.ToInt32(this.comboBox1.SelectedItem));
                this.dataGridView1.DataSource = students;
            }
        }
    }
}
